from django.db import models

# Create your models here.
class User(models.Model):
    username=models.CharField(max_length=100)
    password=models.CharField(max_length=100)

class Sort(models.Model):
    sname=models.CharField(max_length=100)
    sid=models.ForeignKey('self',on_delete=models.SET_NULL,null=True)
    stime=models.DateTimeField(auto_now_add=True)

class Goods(models.Model):
    gname=models.CharField(max_length=100)
    gid=models.ForeignKey(Sort,on_delete=models.CASCADE,related_name='a1')
    gprice=models.DecimalField(max_digits=10,decimal_places=2)
    gnum=models.IntegerField()
    gtime=models.DateTimeField(auto_now_add=True)
    uptime=models.DateTimeField(auto_now=True)


class Order(models.Model):
    oid=models.ForeignKey(Goods,on_delete=models.CASCADE,related_name='a2')
    onum=models.IntegerField()
    oprice=models.DecimalField(max_digits=10,decimal_places=2)
    oname=models.CharField(max_length=100)
    uid=models.ForeignKey(User,on_delete=models.CASCADE,related_name='a3')
    otime=models.DateTimeField(auto_now_add=True)